/**
 * create by young (young2f@outlook.com) on 2020/9/16
 * 对账单
 */


'use strict';
import React from 'react';
import {Button, Form, Input, InputNumber, notification} from 'antd';

import {FormField, FormLayout, ModalFooter} from 'antd-extra';
import FormBase from '../../../components/Base/FormBase';
import {connect} from "dva";
import moment from 'moment';
import 'moment/locale/zh-cn';
import UploadPic from "../../../components/UploadPic";

moment.locale('zh-cn');
const table = 'Customer';
@Form.create()
@connect(({user, global, dynamicLabel, customer}) => ({...user, ...customer, ...dynamicLabel, ...global}))
export default class ModalCreateOrEditStatementRecord extends FormBase {
  constructor(props) {
    super(props);
    const {record} = props;
    this.state = {...record};
  }

  renderFoot = () => {
    const {foot, value, modalRef, callback, form} = this.props;

    if (foot) {
      return foot(value, modalRef);
    } else {
      return (
        <ModalFooter>
          <Button type="primary" onClick={() => {
            form.validateFields((err, values) => {
              if (err) {
                const {code} = err;
                const {errors} = code;
                errors.forEach(item => {
                  notification.error(item);
                });
                return;
              }
              const {fileList = []} = this.state;
              values.fileList = fileList;
              callback(values);
              modalRef.close();
            });
          }}>确定</Button>
          <Button onClick={() => {
            modalRef.close();
          }}>取消</Button>
        </ModalFooter>
      );
    }
  };


  render() {
    const {form, style, cols = 1} = this.props;
    const {code, recordId, amount, fileList} = this.state;

    return (
      <div style={{...style}}>
        {<FormLayout form={form} cols={cols}>
          <FormField
            label={'客户编码'}
            name={'code'}
            initialValue={code}
          >
            <Input disabled style={{width: '100%'}}
            ></Input></FormField>

          <FormField
            label={'记录编码'}
            name={'recordId'}
            initialValue={recordId}
          >
            <Input disabled style={{width: '100%'}}
            ></Input></FormField>
          <FormField
            label={'对账金额'}
            name={'amount'}
            initialValue={amount}
            required={true}
          >
            <InputNumber style={{width: '100%'}}
            ></InputNumber></FormField>

        </FormLayout>}
        <UploadPic title={'上传对账单'} fileList={fileList}
                   callback={f => this.state.fileList = f.fileList}></UploadPic>
        {this.renderFoot()}
      </div>

    );
  }
}

